﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Yugi_Gui.Sort_Search
{
    partial class Sort
    {
        private bool canswapT(List<System.Windows.Controls.UserControl> list, int[] a, int i, int j)
        {
            if (i == j)
                return true;
            int[] b = new int[20];
            if (list[i] is WpfApplication1.Table)
            {
                Yugi.Client.WebSerive.TableInfo tableinfo1 = (Yugi.Client.WebSerive.TableInfo)((WpfApplication1.Table)list[i]).DataContext;
                Yugi.Client.WebSerive.TableInfo tableinfo2 = (Yugi.Client.WebSerive.TableInfo)((WpfApplication1.Table)list[j]).DataContext;
                for (int t = 0; t < a.Length; t++)
                {
                    b[t] = compare(a[t], tableinfo1.TableID, tableinfo2.TableID, (int)VALUE_CP.TableID);
                    if (b[t] == 0)
                        b[t] = compare(a[t], tableinfo1.NickName1, tableinfo2.NickName1, (int)VALUE_CP.NickName);
                }
            }
            for (int u = 0; u < b.Length; u++)
            {
                if (b[u] == 1)
                    return true;
                if (b[u] == -1)
                    return false;
            }
            return false;
        }

        private int compare(int way, object a, object b, int check)
        {
            if (Math.Abs(way) == check)
            {
                if (way > 0 && a.ToString().CompareTo(b.ToString()) == -1)
                    return 1;
                if (way < 0 && a.ToString().CompareTo(b.ToString()) == 1)
                    return 1;
                if (way > 0 && a.ToString().CompareTo(b.ToString()) == 1)
                    return -1;
                if (way < 0 && a.ToString().CompareTo(b.ToString()) == -1)
                    return -1;
            }
            return 0;
        }
        public enum VALUE_CP
        {
            TableID = 1,
            NickName = 2
        }
        public static int Reduction(Sort_Search.Sort.VALUE_CP p)
        {
            return (int)p;
        }
        public static int Increase(Sort_Search.Sort.VALUE_CP p)
        {
            return -(int)p;
        }
    }
}
